//
//  ZLPGuideViewController.m
//  TangYi
//
//  Created by dllo on 15/11/4.
//  Copyright © 2015年 赵连鹏. All rights reserved.
//

#import "ZLPGuideViewController.h"
#import "ZLPHomeViewController.h"
#import "ZLPFindViewController.h"
#import "ZLPSearchViewController.h"
#import "ZLPUserViewController.h"

@interface ZLPGuideViewController ()<UIScrollViewDelegate>

@end

@implementation ZLPGuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.imageView = [[UIImageView alloc]init];
    self.imageView.image = [UIImage imageNamed:@"new_feature_background.png"];
    //设置imageview的尺寸【自动设置宽度】
    self.imageView.frame = [UIScreen mainScreen].applicationFrame;
    NSLog(@"wwwwwww%@",NSStringFromCGRect(self.imageView.frame));
    //设置交互_
    self.imageView.userInteractionEnabled = YES;
   
    [self.view addSubview: self.imageView];
    self.scroll =[[UIScrollView alloc]init];
    //设置的是点
    //    scroll.frame = self.view.bounds;
    self.scroll.frame = [UIScreen mainScreen].applicationFrame;
    // NSLog(@"%@",NSStringFromCGRect(scroll.frame));
    //隐藏水平条
    self.scroll.showsHorizontalScrollIndicator = NO;
    //设置尺寸[防止这个图片尺寸的循环]
    CGSize size =_scroll.frame.size;
    //设置scroll的滚动内容[垂直方向为0，水平方向设置值，进行滚动]
    self.scroll.contentSize = CGSizeMake(size.width * 4, 0);
    //添加使用分页
    self.scroll.pagingEnabled = YES;
    //监听scroll的代理【滚动代理】
    self.scroll.delegate = self;
    //调试
    //    NSLog(@"scroll的文本尺寸%@",NSStringFromCGSize(scroll.contentSize));
    [self.imageView addSubview:self.scroll];
    
    
    
    NSLog(@"%@",NSStringFromCGSize(size));
    for (int i = 0; i < 4; i++)
    {
        UIImageView *imageView1 = [[UIImageView alloc]init];
        //显示图片名字【图片名拼串】
        NSString *name = [NSString stringWithFormat:@"start%d.png",i + 1];
        imageView1.image = [UIImage imageNamed:name];
        //设置frame
        imageView1.userInteractionEnabled = YES;
        imageView1.frame = CGRectMake(i*size.width, 0, size.width, size.height);
        [self.scroll addSubview:imageView1];
        if (i == 4 - 1)
        {
            //最后一页，添加2个按钮
            //3.立即体验
            UIButton *startBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
            UIImage *startNormal = [UIImage imageNamed:@"new_feature_finish_button.png"];
            [startBtn setBackgroundImage:startNormal forState:(UIControlStateNormal)];
            //长按高量
//            [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted.png"] forState:UIControlStateHighlighted];
            startBtn.center = CGPointMake(size.width * 0.5, size.height * 0.8);
            startBtn.bounds = (CGRect){CGPointZero,startNormal.size};
            [startBtn addTarget:self action:@selector(start) forControlEvents:(UIControlEventTouchUpInside)];
            [imageView1 addSubview:startBtn];
            //交互
            self.imageView.userInteractionEnabled=YES;
        }
    }
    
    CGSize size1 = self.view.frame.size;
    self.page = [[UIPageControl alloc]init];
    //设置中心点【保证屏幕适配】
    self.page.center = CGPointMake(size1.width*0.5, size1.height*0.95);
    //设置指示器的数目
    self.page.numberOfPages = 4;
    //设置边框【bounds的前面永远是0，0】【page的高度是固定的，不能更改】
    self.page.bounds = CGRectMake(0, 0, 150, 0);
    //修改颜色【当前指示器的颜色】
//    self.page.currentPageIndicatorTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"new_feature_pagecontrol_checked_point.png"]];
//    //【平普通指示器的颜色】
//    self.page.pageIndicatorTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"new_feature_pagecontrol_point.png"]];
    [self.view addSubview:self.page];
    
}
- (void)start
{
    NSLog(@"开始Memory");
    //    [UIApplication sharedApplication].keyWindow
    /*
     有显示状态栏时创建控制器，控制器view的高度：460
     没有显示状态栏时创建控制器，控制器view的高度：480
     */
    // 显示状态栏
    [UIApplication sharedApplication].statusBarHidden = NO;
    
    ZLPHomeViewController *homeVC = [[ZLPHomeViewController alloc] init];
    UINavigationController *homeNaVC = [[UINavigationController alloc] initWithRootViewController:homeVC];
    homeNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed:@"homepage.png"] tag:1000] autorelease];
    
    ZLPFindViewController *findVC = [[ZLPFindViewController alloc] init];
    UINavigationController *findNaVC = [[UINavigationController alloc] initWithRootViewController:findVC];
    findNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"发现" image:[UIImage imageNamed:@"find.png"] tag:1001] autorelease];
    
    ZLPUserViewController *userVC = [[ZLPUserViewController alloc] init];
    UINavigationController *userNaVC = [[UINavigationController alloc] initWithRootViewController:userVC];
    userNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"个人中心" image:[UIImage imageNamed:@"user.png"] tag:1002] autorelease];
    
    ZLPSearchViewController *searchVC = [[ZLPSearchViewController alloc] init];
    UINavigationController *searchNaVC = [[UINavigationController alloc] initWithRootViewController:searchVC];
    searchNaVC.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"搜索" image:[UIImage imageNamed:@"search.png"] tag:1003] autorelease];
    
    UITabBarController *tab = [[UITabBarController alloc] init];
    tab.viewControllers = @[homeNaVC, findNaVC, searchNaVC, userNaVC];
    
    self.view.window.rootViewController = tab;
    
    // 控制器的view是延迟加载：需要显示的\用到的时候才会加载
//    self.view.window.rootViewController = [[UINavigationController alloc]initWithRootViewController:[[ZLPHomeViewController alloc] init] ];
  
}



//滚动时候的调用的方法
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //设置分页【跟着滚动视图和分页的数目变化而变化】
    self.page.currentPage = scrollView.contentOffset.x / scrollView.frame.size.width;
}

//设置状态栏是否隐藏
-(BOOL)prefersStatusBarHidden
{
    return YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
